//
//  MU_picBlock.m
//  fistboard
//
//  Created by Qian Kun on 13-7-24.
//  Copyright (c) 2013年 iwind. All rights reserved.
//

#import "MU_picBlock.h"
#import "XDTools.h"
@implementation MU_picBlock

@synthesize mu_title = _mu_title;
@synthesize delegate = _delegate;
@synthesize mu_imgURL = _mu_imgURL;
@synthesize mu_index = _mu_index;
@synthesize mu_info = _mu_info;

-(id)initWithOrigin:(CGPoint )initialPoint atIndex:(int)index andTitle:(NSString *)title andImageURL:(NSString *)imgURL
{
    self = [super initWithFrame:CGRectMake(initialPoint.x, initialPoint.y, dWidth, dHeight)];
    if (self) {
        _mu_imgURL = imgURL;
        _mu_title = title;
        _mu_index = index;
        
        bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, dWidth, dHeight)];
        //背景图片
        bgView.image = dImageBg;
        
        label=[[UILabel alloc]initWithFrame:CGRectMake(0, dHeight-dLabelHeight, dWidth, dLabelHeight)];
        
        label.text=title;
//        label.textColor = dColorTextTitle;
        label.font= dFontLabel;
//        label.textAlignment=UITextAlignmentCenter;
        label.numberOfLines = 2;//两行
        label.backgroundColor=[UIColor clearColor];
        
        //图片操作
        imgView = [[UIImageView alloc] initWithFrame:CGRectMake(dImgGap, dImgGap, dWidth-2*dImgGap, dHeight-dLabelHeight-dImgGap)];
//        imgView.contentMode = UIViewContentModeScaleToFill;
        NSString * imageUrl = [NSString stringWithFormat:@"%@%@",ImageMainUrl,imgURL];
        NSString * urlstring = [imageUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        imgView.tag = 200;
        [imgView setImageWithURL:[NSURL URLWithString:urlstring] placeholderImage:nil];

//        [imgView setImageWithURL:[NSURL URLWithString:imgURL] placeholderImage:dPic_imagePlaceHolder];
        [self addSubview:bgView];
        [self addSubview:label];
        [self addSubview:imgView];
        
//        self.backgroundColor=[UIColor colorWithRed:255.0/255.0 green:220.0/255.0 blue:245.0/255.0 alpha:20];
//        self.layer.cornerRadius=7.0f;
//        self.layer.masksToBounds=YES;
//        self.layer.borderWidth=1;
//        self.layer.borderColor=[[UIColor grayColor]CGColor];
        
    }
    
    return self;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    //点击进入详情
    [self.delegate onClick:self];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        //self.backgroundColor=[UIColor colorWithRed:255.0/255.0 green:240.0/255.0 blue:245.0/255.0 alpha:20];
    }
    return self;
}

#pragma mark -- set & get methods
-(void)setMu_title:(NSString *)mu_title
{
    if (![mu_title isEqualToString:_mu_title]) {
        _mu_title = [mu_title copy];
        label.text = mu_title;
    }
}
-(void)setMu_imgURL:(NSString *)mu_imgURL
{
    if (![mu_imgURL isEqualToString:_mu_imgURL]) {
        _mu_imgURL = [mu_imgURL copy];
        NSString * imageUrl = [NSString stringWithFormat:@"%@%@",ImageMainUrl,_mu_imgURL];
        NSString * urlstring = [imageUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        imgView.tag = 200;
        [imgView setImageWithURL:[NSURL URLWithString:urlstring] placeholderImage:nil];
//        [imgView setImageWithURL:[NSURL URLWithString:mu_imgURL] placeholderImage:dPic_imagePlaceHolder];
    }
}


@end
